﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.DirectX.Direct3D;


namespace Laboratorium1
{
    class Sphere : Figure
    {

        public override void generate()
        {
            int numSegments = 64;
            double theta = 0.0, phi = 0.0, r = 1.0;
            double ratio = (2 * Math.PI) / numSegments;

            int numVerts = (numSegments * numSegments) / 2 - numSegments + 2;
            int numFaces = (numSegments * numSegments) - (numSegments * 2);

            Point3D point;
            this.points = new List<Point3D>();

            for (int i = 0; i < numVerts / numSegments; ++i)
            {
                phi += ratio;
                for (int j = 0; j < numSegments; ++j)
                {
                    point = new Point3D();
                    theta += ratio;
                    int indx = (i * numSegments) + j + 1; 

                    point.x = (float)(r * Math.Sin(phi) * Math.Cos(theta));
                    point.y = (float)(r * Math.Sin(phi) * Math.Sin(theta));
                    point.z = (float)(r * Math.Cos(phi));
                    points.Add(point);
                }

                theta = 0.0f;
            }
        }
    }
}
